"""
Copyright (c) 2023 - present SKbioinfo
"""

from flask_restful import Resource, request
from flask import jsonify
from apps.API.utils.log_helper import lg
from apps.API.connector.db_common import *
from flask_jwt_extended import jwt_required

'''
    Update permission
'''
class interfaceSetPermiss(Resource):
    '''
        POST: set permission
    '''
    @jwt_required()
    def post(self):
        try:
            permiss=",".join(request.json["permiss"])
            update_permiss_sql='''
                UPDATE {table_name} set permissions=\"{permiss}\" WHERE name=\"{role_id}\"
            '''.format(
                table_name="roles",
                permiss=permiss,
                role_id=request.json["role_id"]
            )
            res=update_info(update_permiss_sql)
            return res
        except Exception as e:
            lg.error(e)
            
            